//
//  TMToCompletedCell.m
//  国学商家管理
//
//  Created by Tao Li on 2018/6/28.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMToCompletedCell.h"
#import "TMMyOrderModel.h"
#import "UIView+STShadow.h"
#import "TMGlobalMacro.h"
@implementation TMToCompletedCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.applyMoneyBackBtn.layer.cornerRadius = 3.0f;
    self.applyMoneyBackBtn.layer.masksToBounds = YES;
    self.commentBtn.layer.cornerRadius = 3.0f;
    self.commentBtn.layer.masksToBounds = YES;
    self.courseImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.courseImageView.clipsToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)moneyBackAction:(UIButton *)sender {
    if (self.model.evil == 1) {
        return;
    }
    if (self.backBlock) {
        self.backBlock();
    }
}
- (IBAction)commentAction:(UIButton *)sender {
    if (self.comBlock) {
        self.comBlock();
    }
}
- (void)setStates:(CompelteState)states{
    _states = states;
}
- (void)setModel:(TMMyOrderModel *)model{
    _model = model;
    if (self.model.pic.count > 0) {
        [self.courseImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithBaseUrl:self.model.pic[0]]] placeholderImage:kPlaceholder];
    }
    self.courseTitleLabel.text = self.model.name;
    self.coursePriceLabel.text = [NSString stringWithFormat:@"%.02f", self.model.price];
    self.timeLabel.text = [NSString stringWithFormat:@"时间:%@", [SPToolSet stringFromDateString:model.create_time]];
    self.moneyBackStates.hidden = YES;
   // model.status 1 待完成 2待评价 3完成 4退款
    if (_states == 1) {
        //216-50
        //确认完成 和申请退款 按钮 无订单号
        self.moneyBackLabel.hidden = YES;
        self.orderNumLabel.hidden = YES;
        self.topLineView.hidden = YES;
        self.topConst.constant = 12;
        [self.commentBtn setTitle:@"确认完成" forState:UIControlStateNormal];
        self.applyMoneyBackBtn.backgroundColor = [UIColor whiteColor];
         [self.applyMoneyBackBtn setTitle:@"申请退款" forState:UIControlStateNormal];
        [self.applyMoneyBackBtn setTitleColor:[UIColor hx_colorWithHexRGBAString:@"#05B48D"] forState:UIControlStateNormal];
        self.applyMoneyBackBtn.layer.borderColor = [UIColor hx_colorWithHexRGBAString:@"#05B48D"].CGColor;
        self.applyMoneyBackBtn.layer.borderWidth = 1.0f;
    }
    if (_states == 2) {
        //216
        //订单号 交易完成  评价按钮
        self.orderNumLabel.text = [NSString stringWithFormat:@"订单号:%@", model.number];
        self.applyMoneyBackBtn.hidden = NO;
        if (self.model.evil == 0) {
            [self.applyMoneyBackBtn setTitle:@"投诉" forState:UIControlStateNormal];
        }else{
            [self.applyMoneyBackBtn setTitle:@"已投诉" forState:UIControlStateNormal];
        }
        if (self.model.tip == 0) {
            [self.commentBtn setTitle:@"评论" forState:UIControlStateNormal];
        }else{
            [self.commentBtn setTitle:@"已评论" forState:UIControlStateNormal];
        }
    }
    if (_states == 3) {
        //订单号 交易完成。无按钮 + 投诉按钮！！！！！
        //216-61.5- 13.5;
        self.orderNumLabel.text = [NSString stringWithFormat:@"订单号%@", model.number];
        self.buttomLineView.hidden = NO;
        self.applyMoneyBackBtn.hidden = YES;
        //self.commentBtn.hidden= YES;
       // self.buttomConst.constant = 10;
        if (self.model.evil == 0) {
            [self.commentBtn setTitle:@"投诉" forState:UIControlStateNormal];
        }else{
            [self.commentBtn setTitle:@"已投诉" forState:UIControlStateNormal];
        }
    }
    if (_states == 4) {
        //订单号 退款完成和 退款中。无按钮
        //216-61.5- 13.5;
        self.orderNumLabel.text = [NSString stringWithFormat:@"订单号%@", model.number];
        self.buttomLineView.hidden = NO;
        self.applyMoneyBackBtn.hidden = YES;
       [self.commentBtn setTitle:@"取消退款" forState:UIControlStateNormal];
        self.commentBtn.hidden= YES;
       // self.buttomConst.constant = 10;
        //0未发起退款 1发起退款 2退款中 3退款完成
        if ( self.model.ret == 1) {
            self.moneyBackStates.hidden = NO;
            self.moneyBackStates.text = @"退款中";
            self.buttomLineView.hidden = NO;
            self.commentBtn.hidden= NO;
           // self.buttomConst.constant = 10;
        }else if(self.model.ret == 2){
            self.moneyBackStates.hidden = NO;
            self.moneyBackStates.text = @"退款完成";
            self.buttomLineView.hidden = YES;
            self.commentBtn.hidden= YES;
            self.buttomConst.constant = 10;

        }
        else if(self.model.ret == 3){
            self.moneyBackStates.hidden = NO;
            self.moneyBackStates.text = @"退款完成";
            self.buttomLineView.hidden = YES;
            self.commentBtn.hidden= YES;
            self.buttomConst.constant = 10;
            
        }else{
            
            self.moneyBackStates.hidden = YES;
        }
    }
    
    [self.commentBtn setBackgroundColor:UIColor.whiteColor];
    [self.commentBtn st_setBrderWidth:0.5 borderColor:TM_thirdTextColor];
    [self.commentBtn setTitleColor:TM_firstTextColor forState:UIControlStateNormal];
}
- (void)layoutSubviews{
    [self.commentBtn setBackgroundColor:UIColor.whiteColor];
    [self.commentBtn st_setBrderWidth:0.5 borderColor:TM_thirdTextColor];
    [self.commentBtn setTitleColor:TM_firstTextColor forState:UIControlStateNormal];
}
@end
